{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# MIP的事件数组，转换为插入语句，用来查找插入失败的原因\n",
    "输入两个参数：\n",
    "- tableName:表名\n",
    "- jsonString：json字符串，直接把数组赋值进去"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "insert into x_kh_BusinessRefundPlanning (BusinessRefundPlanningGUID,CreatedGUID,CreatedName,CreatedTime,ModifiedGUID,ModifiedName,ModifiedTime,x_ShortCustomer,x_ShortCustomerGUID,x_BusinessPlanningGUID,x_SignPlanningGUID,x_PlanRefundAmount,x_PlanRefundDate,x_Remark,x_PlanRefundAmountThisYear,x_ContractGUID,x_IsHistoryContract,x_StagePayPlanGUID)\n",
      " values('fa1263e1-544c-4f4e-a3e8-756f478e5c1a','4230bc6e-69e6-46a9-a39e-b929a06a84e8','系统管理员','2022-12-17T09:56:09.75','4230bc6e-69e6-46a9-a39e-b929a06a84e8','系统管理员','2022-12-17T09:56:09.75','中南锦时','f16bf52d-bc93-ec11-b4db-bc931b925d9d','6e0c759f-bbec-4561-fb91-08dad720e08f',null,0,null,null,null,'bf8e6643-865d-4428-8902-037fb6b7c21b',1,'c1c831f5-e40b-4059-be9f-5f12dcebb5af')\n",
      "\n",
      "insert into x_kh_BusinessRefundPlanning (BusinessRefundPlanningGUID,CreatedGUID,CreatedName,CreatedTime,ModifiedGUID,ModifiedName,ModifiedTime,x_ShortCustomer,x_ShortCustomerGUID,x_BusinessPlanningGUID,x_SignPlanningGUID,x_PlanRefundAmount,x_PlanRefundDate,x_Remark,x_PlanRefundAmountThisYear,x_ContractGUID,x_IsHistoryContract,x_StagePayPlanGUID)\n",
      " values('73612a23-061a-49fd-aba9-ccdf1909a0b2','4230bc6e-69e6-46a9-a39e-b929a06a84e8','系统管理员','2022-12-17T09:56:09.75','4230bc6e-69e6-46a9-a39e-b929a06a84e8','系统管理员','2022-12-17T09:56:09.75','中南锦时','f16bf52d-bc93-ec11-b4db-bc931b925d9d','6e0c759f-bbec-4561-fb91-08dad720e08f',null,0,null,null,null,'44fbcdcb-8f51-49f2-868c-031f9b2a791c',1,'e56e4b52-fd0e-4f86-b1d4-7485ab3d35bb')\n",
      "\n"
     ]
    }
   ],
   "source": [
    "\n",
    "import json\n",
    "\n",
    "tableName='表名'\n",
    "jsonString='''\n",
    "\t完整的json数组\n",
    "'''\n",
    "\n",
    "jsonList=json.loads(jsonString)\n",
    "\n",
    "resultFormat='insert into {tablename} ({fields})\\r\\n values({values})\\r\\n'\n",
    "for data in jsonList:\n",
    "\tfields=','.join(data[\"Data\"].keys())\n",
    "\tvalues=\",\".join(map(lambda x:\"'\"+str(x)+\"'\" if type(x)==str else str(x) if x!=None else 'null' ,(data[\"Data\"].values())))\n",
    "\tprint (resultFormat.format(tablename=tableName,fields=fields,values=values))\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.8.5 ('base')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "316f8cea0fe2de1197333f65c5229a920e40fdfa2bfa4a2c178e7e0f5f8e97d1"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
